import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_shop/common/index.dart';
import 'package:flutter_shop/common/utils/webview_screen.dart';
import 'package:flutter_shop/pages/address_page.dart';

class MemberPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text('会员中心'),
      ),
      body: ListView(
        children: <Widget>[
          _topHeader(context),
          _orderTitle(),
          _orderType(),
          _actionList(context)
        ],
      ),
    );
  }

  //头像区域

  Widget _topHeader(BuildContext context) {
    return Container(
      width: ScreenUtil().setWidth(750),
      padding: EdgeInsets.all(20),
      color: Theme.of(context).primaryColor,
      child: Column(
        children: <Widget>[
          Container(
            margin: EdgeInsets.only(top: 30),
            child: ClipOval(
                child: Icon(
              Icons.perm_identity,
              color: Colors.white,
              size: ScreenUtil().setWidth(80),
            )),
          ),
          Container(
            margin: EdgeInsets.only(top: 10),
            child: Text(
              'xxx',
              style: TextStyle(
                fontSize: ScreenUtil().setSp(36),
                color: Colors.white,
              ),
            ),
          )
        ],
      ),
    );
  }

  //我的订单顶部
  Widget _orderTitle() {
    return Container(
      margin: EdgeInsets.only(top: 10),
      decoration: BoxDecoration(
          color: Colors.white,
          border: Border(bottom: BorderSide(width: 1, color: Colors.black12))),
      child: ListTile(
        leading: Icon(Icons.list),
        title: Text('我的订单'),
        trailing: Icon(Icons.arrow_right),
      ),
    );
  }

  Widget _orderType() {
    var oneItemWidth = ScreenUtil.screenWidthDp / 4;
    return Container(
      margin: EdgeInsets.only(top: 5),
      width: ScreenUtil.screenWidthDp,
      height: ScreenUtil().setHeight(120),
      padding: EdgeInsets.only(top: 20),
      color: Colors.white,
      child: Row(
        children: <Widget>[
          Container(
            width: oneItemWidth,
            child: Column(
              children: <Widget>[
                Icon(
                  Icons.party_mode,
                  size: 30,
                ),
                Text('待付款'),
              ],
            ),
          ),
          //-----------------
          Container(
            width: oneItemWidth,
            child: Column(
              children: <Widget>[
                Icon(
                  Icons.query_builder,
                  size: 30,
                ),
                Text('待发货'),
              ],
            ),
          ),
          //-----------------
          Container(
            width: oneItemWidth,
            child: Column(
              children: <Widget>[
                Icon(
                  Icons.directions_car,
                  size: 30,
                ),
                Text('待收货'),
              ],
            ),
          ),
          Container(
            width: oneItemWidth,
            child: Column(
              children: <Widget>[
                Icon(
                  Icons.content_paste,
                  size: 30,
                ),
                Text('待评价'),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _myListTile(String title, Function onTap) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        decoration: BoxDecoration(
            color: Colors.white,
            border:
                Border(bottom: BorderSide(width: 1, color: Colors.black12))),
        child: ListTile(
          leading: Icon(Icons.blur_circular),
          title: Text(title),
          trailing: Icon(Icons.arrow_right),
        ),
      ),
    );
  }

  Widget _actionList(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: 10),
      child: Column(
        children: <Widget>[
          _myListTile('领取优惠券', () {
            TopReminder.warning(context, "领取优惠券");
          }),
          _myListTile('已领取优惠券', () {
            TopReminder.warning(context, "已领取优惠券");
          }),
          _myListTile('地址管理', () {
            RouteUtil.push(context, AddressPage());
          }),
          _myListTile('关于我们', () {
            RouteUtil.push(
                context,
                WebViewScreen(
                  title: '关于我们',
                  url: 'https://baidu.com',
                ));
//            TopReminder.warning(context, "关于我们");
          }),
        ],
      ),
    );
  }
}
